﻿


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using Freeform;


namespace Space_in_Shaders 
{
    public class Fader : SpaceObject
    {

        #region Members

        public Int32 LifeTime { get; private set; }
        public Int32 Remaining { get; set; }
        public Color StartColour { get; set; }
        public Color EndColour { get; set; }

        #endregion


        #region Init

        public Fader(SpaceWorld World, Int32 LifeTime)
            : base(World)
        {
            this.LifeTime = LifeTime;
            Remaining = LifeTime;
            StartColour = Color.White;
            EndColour = new Color(Vector4.Zero);
        }

        #endregion


        #region Update

        public override void Update(GameTime time)
        {
            base.Update(time);

            Remaining -= time.ElapsedGameTime.Milliseconds;

            Vector4 Start = StartColour.ToVector4();
            Vector4 End = EndColour.ToVector4();
            Vector4 Now = End - (End - Start) * ((Single)Remaining / (Single)LifeTime);

            Actor.ColourOverlay = new Color(Now);

            if (Remaining < 0)
                Destroy();
        }

        #endregion

    }
}